#!/bin/sh

#edit the following variables to suit your needs
MYUID=1000              # your user uid
MYGID=100               # your user gid
MYLOGIN=wangdian        # your login
TERM=terminal           # your terminal emulator
MYSHELL=bash            # your shell
export DISPLAY=:0       # your X display


TMPFILE=/run/automount.$RANDOM
DIR=`cat /etc/fstab | grep -v '#' | grep $* | awk '{print $2;}'`
if [ "x$DIR" = "x" ]; then
        MYUUID=`blkid -o value -s UUID $*`
        if [ "x$MYUUID" = "x" ]; then
                MYUUID="unknown"
        fi
        DIR=/run/media/$MYUUID
fi
mkdir -p /run/media
mkdir -p $DIR
cat > $TMPFILE << EOF
#!/bin/sh
echo "$* will be mounted on $DIR. "
sudo /bin/mount -o uid=$MYUID,gid=$MYGID $* $DIR
cd $DIR
$MYSHELL
cd
sudo /bin/umount $DIR
EOF
chmod a+x $TMPFILE
su $MYLOGIN -c "$TERM -T 'Terminal - $* mounted on $DIR' -e $TMPFILE"
sleep 1; rm -f $TMPFILE
